#include <bits/stdc++.h>
using namespace std;
const int NN = 7500 + 10;
int N, K, Vis[NN];
#define _all(i, a, b) for (int i = (a); i <= (int)(b); ++i)
using LL = long long;
const LL MOD = 2019201997, A = 2019201913LL, B = 2019201949LL;
LL D[NN];
LL prim() {  // Prim/Jarnik MST algorithm
  _all(i, 1, N) D[i] = MOD;
  _all(iter, 1, N) {
    int mi = 0;
    _all(i, 1, N) if (!Vis[i] && (mi == 0 || D[i] < D[mi])) mi = i;
    Vis[mi] = 1;
    _all(i, 1, N) if (!Vis[i]) {
      // cout << "mi: " << mi << endl;
      // cout << "Before: " << D[i] << endl;
      D[i] = min(D[i], (A * min(mi, i) % MOD + B * max(mi, i)) % MOD) % MOD;
      // cout << "After: " << D[i] << endl;
    }
  }
  sort(D + 1, D + N + 1);
  return D[N + 1 - K];
}
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> N >> K;
  cout << prim() << "\n";
  return 0;
}
